import { getSblxBySbzlx } from '../../../../../mapUtils/SblxUtil';
import IpmsLineString from '../IpmsLineString';
import RuleResult from '../vo/RuleResult';

/**
 * 电缆廊道修改
 * @implements {IpmsPoint}
 */
class PmsDlld extends IpmsLineString {
  constructor(_) {
    super(_);
    this.defaultSbzlx = 91000000;
    this.drawtype = 'pms_dlld';
    this.defaultName = '新增电缆廊道';
    this.defaultLineColor = '#ff0000';
    this.defaultLineWidth = 3;
    this.defaultLineOpacity = 1;
  }

  /**
   * 新增电缆廊道
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  draw(option, snapList) {
    this.option = option;
    this.properties = Object.assign({}, this.properties, this.option);
    return super.draw(option, snapList);
  }

  /**
   * 编辑电缆廊道
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  edit(option, snapList) {
    this.option = option;
    return super.edit(option, snapList);
  }

  /**
   * 获取当前绘制设备信息
   * @override
   */
  async getTargetDevice() {
    return {
      schema: this.option.schema,
      ghrw: this.option.ghrw || '',
      ssfa: this.option.ghfa || '',
      ssxm: this.option.ghxm || '',
      ghnf: this.option.ghnf || '',
      ssdw: this.option.ssdw || '',
      fxlx: this.option.fxlx || 2,
      oid: this.option.oid || '',
      sblx: getSblxBySbzlx(this.defaultSbzlx),
      sbzlx: this.defaultSbzlx,
      sbmc: this.defaultName,
      shape: this.getGeometryWkt(this.geometry),
      tdcd: turf.length(this.geometry),
      tdlx: this.option.tdlx || '',
      ssqy: this.option.ssqy || ''
    };
  }

  /**
   * 设备样式设置
   * @override
   */
  setDrawStyle() {
    var layerConfig = {
      id: 'draw_layer_' + this.drawtype,
      type: 'line',
      filter: ['all', ['==', '$type', 'LineString'], ['==', 'user_drawtype', this.drawtype]],
      paint: {
        'line-color': '#ff0000',
        'line-width': 100,
        'line-pattern': ['get', 'user_pattern']
      }
    };
    this._setupLayerConfig(layerConfig, 'hot');
    this._setupLayerConfig(layerConfig, 'cold');
  }

  /**
   * 新增电缆廊道验证点合理性
   * @override
   * @param {Number} index 点下标
   * @param {*} snap 捕捉到的设备
   */
  async _ruleJudgeDrawPoint(index) {
    return new RuleResult(true, index, 'success');
  }

  /**
   * 验证编辑点的合理性
   * @override
   * @param {*} snap 捕捉到的设备
   */
  async _ruleJudgeEditPoint() {
    return new RuleResult(true, 0, 'success');
  }

  /**
   * 验证所有点合理性
   * @override
   */
  _ruleJudgeAllPoint() {
    return new RuleResult(true, 0, 'success');
  }
}

export default PmsDlld;
